//
//  BVMyOrderCell.m
//  BuyVegetables
//
//  Created by 叶思超 on 15/10/13.
//  Copyright (c) 2015年 叶思超. All rights reserved.
//

#import "BVMyOrderCell.h"
#import "BVConst.h"
#import "BVMyOrder.h"

@interface BVMyOrderCell ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
// 订单编号
@property (weak, nonatomic) IBOutlet UILabel *myOrderID;
// 商品信息
@property (weak, nonatomic) IBOutlet UILabel *shopInfo;
// 价格
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
// 时间
@property (weak, nonatomic) IBOutlet UILabel *orderTimeLabel;
// 状态
@property (weak, nonatomic) IBOutlet UILabel *statuseLabel;


@end

@implementation BVMyOrderCell

- (void)awakeFromNib {
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];
    self.bgView.backgroundColor = BVColor(233, 234, 235);
    
    self.confirmClick.layer.masksToBounds = YES;
    self.confirmClick.layer.cornerRadius = 4;
    
    self.nextOrder.layer.masksToBounds = YES;
    self.nextOrder.layer.cornerRadius = 4;
    self.nextOrder.layer.borderColor = BVBaseOrangeColor.CGColor;
    self.nextOrder.layer.borderWidth = 1;
    
    self.cancelBtn.layer.masksToBounds = YES;
    self.cancelBtn.layer.cornerRadius = 4;
    self.cancelBtn.layer.borderColor = BVBaseOrangeColor.CGColor;
    self.cancelBtn.layer.borderWidth = 1;
}

+ (instancetype)cell {
    return [[[NSBundle mainBundle] loadNibNamed:@"BVMyOrderCell" owner:nil options:nil] lastObject];
}

- (void)setMyOrder:(BVMyOrder *)myOrder {
    _myOrder = myOrder;
    
    // 订单编号
    self.myOrderID.text = [NSString stringWithFormat:@"订单编编号:%@",  myOrder.ordernum];
    
    // 商品信息
    self.shopInfo.text = [NSString stringWithFormat:@"%@等", myOrder.title_arr];
    
    // 价格
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@", myOrder.money];
    
    // 时间
    self.orderTimeLabel.text = myOrder.order_time;
    
    // 当前状态
    if ([myOrder.status isEqualToString:@"0"]) {
        self.deledButton.hidden = NO;
        self.statuseLabel.text = @"待付款";
        self.confirmClick.hidden = NO;
        self.cancelBtn.hidden = NO;
        [self.confirmClick setTitle:@"去付款" forState:UIControlStateNormal];
    } else if ([myOrder.status isEqualToString:@"1"] || [myOrder.status isEqualToString:@"3"]) {
        self.deledButton.hidden = YES;
        self.statuseLabel.text = @"商家已接单";
        self.confirmClick.hidden = NO;
        self.cancelBtn.hidden = YES;
//        [self.confirmClick setTitle:@"确认收货" forState:UIControlStateNormal];
        //隐藏确认收货
        self.confirmClick.hidden = YES;
    } else if([myOrder.status isEqualToString:@"2"]) {
        self.deledButton.hidden = NO;
        self.statuseLabel.text = @"订单已完成";
        self.confirmClick.hidden = YES;
        self.cancelBtn.hidden = YES;
    }
}
- (IBAction)deleOrder:(id)sender {
    NSLog(@"delete   %@",_myOrder.order_id);
    [self.delegate orderCell:self deleteOrder:_myOrder];
}
//取消确认订单
- (IBAction)confirmOrder:(id)sender {
    NSLog(@"confirm  %@",_myOrder.order_id);
    UIButton * btn = sender;
    if ([btn.titleLabel.text isEqualToString:@"去付款"]) {
        [self.delegate orderCell:self confirmOrder:_myOrder];
    }else{
        [self.delegate orderCell:self confirmReceive:_myOrder];
    }
}
- (IBAction)nextOrder:(id)sender {
    NSLog(@"next   %@",_myOrder.order_id);
    [self.delegate orderCell:self nextOrder:_myOrder];
}
- (IBAction)cancel:(id)sender {
    
    [_delegate orderCell:self cancelBtn:_myOrder];
}

@end
